/*[[ Name := BMX BreakOut2 Author := Copyright © 2005, Lifestatic Link := Use H1 charts Lots := 0.10 Note := Change lots to 1.00 if trading a mini demo acct. Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ // Defines; Defines: ProfitTarget(100); Defines: Slippage(4); // Slippage Defines: StopYear(2005); Defines: dMargin(1500); Defines: FriClose(12); // Hour on friday in which trade halt occurs Vars: i(0),STS(0),BTS(0),BuyOrd(0),SellOrd(0),BuySet(0),SellSet(0),trigger(0); Vars: BuyThisSymbol(0),SellThisSymbol(0),MyStop(0),CounterB(0),CounterS(0); Vars: LowestBuy(0),HighestSell(0),Pips(0),Profit(0); Vars: BuyNewLevel(0),SellNewLevel(0),Set1(0),Set2(0),trigger2(0); Vars: CloseAll(0),TimeClock(0),TimeMin(0),Counter1S(0),Counter1B(0); Vars: LargestMarginUsed(0),LargestFloatingLoss(0); Vars: CloseSwitch(0),CloseSellFirst(0),CloseBuyFirst(0); Vars: LowestFreeMargin(0),HighestBuy(0),LowestSell(0); Vars: PipsNeeded(0),ProfitNeeded(0),OrderBalance(0); Vars: ComSwitch(0),FiveEMA_0(0),FiveEMA_1(0),TwentyEMA_0(0),TwentyEMA_1(0),HundredEMA_0(0),HundredEMA_1(0); // Presets; if year < stopyear then exit; If Curtime - LastTradeTime < 10 then Exit; If Margin > LargestMarginUsed then LargestMarginUsed = Margin; If TotalProfit < LargestFloatingLoss then LargestFloatingLoss = TotalProfit; If LowestFreeMargin == 0 then LowestFreeMargin = FreeMargin; If FreeMargin < LowestFreeMargin then LowestFreeMargin = FreeMargin; FiveEMA_0 = iMAEx(5,MODE_EMA,0,PRICE_CLOSE,0); FiveEMA_1 = iMAEx(5,MODE_EMA,0,PRICE_CLOSE,1); TwentyEMA_0 = iMAEx(20,MODE_EMA,0,PRICE_CLOSE,0); TwentyEMA_1 = iMAEx(20,MODE_EMA,0,PRICE_CLOSE,1); HundredEMA_0 = iMAEx(100,MODE_EMA,0,PRICE_CLOSE,0); HundredEMA_1 = iMAEx(100,MODE_EMA,0,PRICE_CLOSE,1); //////////////////////////////////////////////////////// // Determine Highest Buy and Lowest Sell; //////////////////////////////////////////////////////// LowestBuy = 10; HighestSell = 0; HighestBuy = 0; LowestSell = 10; For i = 1 to TotalTrades { If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY and ord(i,VAL_OPENPRICE) < LowestBuy then LowestBuy = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL and ord(i,VAL_OPENPRICE) > HighestSell then HighestSell = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY and ord(i,VAL_OPENPRICE) > HighestBuy then HighestBuy = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL and ord(i,VAL_OPENPRICE) < LowestSell then LowestSell = ord(i,VAL_OPENPRICE); }; BuyThisSymbol = 0; SellThisSymbol = 0; for i = 1 to TotalTrades { if ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_BUY then BuyThisSymbol = BuyThisSymbol + 1; if ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_SELL then SellThisSymbol = SellThisSymbol + 1; }; If ComSwitch==0 Then Comment("Buy trades: ",BuyThisSymbol,","," Sell trades: ",SellThisSymbol,"Trigger=",",",trigger, "\nLargest Margin Used: ",NumberToStr(LargestMarginUsed,2),","," Largest Floating Loss: ",NumberToStr(LargestFloatingLoss,2),","," Lowest Free Margin: ",NumberToStr(LowestFreeMargin,2), "\nBalance: ",NumberToStr(Balance,2),","," Equity: ",NumberToStr(Equity,2),","," TotalProfit: ",NumberToStr(TotalProfit,2), "\nHighestSell: ",HighestSell,","," LowestBuy: ",LowestBuy, "\nHighestBuy: ",HighestBuy,","," LowestSell: ",LowestSell, "Pips Needed to hit Target:","..",PipsNeeded,"MyStop:",",",MyStop); /////////////////////////////////////////////// // Calculations for pips needed to hit profit target //////////////////////////////////////////////// ProfitNeeded= ProfitTarget - TotalProfit; OrderBalance= (abs(BuyThisSymbol-SellThisSymbol)); PipsNeeded= (Round(abs(ProfitNeeded/OrderBalance))); STS = (SellThisSymbol*3); BTS = (BuyThisSymbol*3); /////////////////////////////////////////////////////// // Modify Orders if Profit Target getting near and Orders are > 19 //////////////////////////////////////////////////////// BuyOrd = 0; SellOrd = 0; for i = 1 to TotalTrades Begin if ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_BUY then BuyOrd++; if ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_SELL then SellOrd++; End; ///////////////////////////////////// // Count Modified Orders Not Used Yet....... ////////////////////////////////////// /* BuySet=0; SellSet=0; for i=1 to TotalTrades Begin If Ord(i,VAL_SYMBOL)==Symbol and Ord(i,VAL_TYPE)==OP_BUY and Ord(i,VAL_STOPLOSS)>0 OR Ord(i,VAL_SYMBOL)==Symbol and Ord(i,VAL_TYPE)==OP_BUY and Ord(i,VAL_TAKEPROFIT)>0 then BuySet=BuySet+1; If Ord(i,VAL_SYMBOL)==Symbol and Ord(i,VAL_TYPE)==OP_SELL and Ord(i,VAL_STOPLOSS)>0 OR Ord(i,VAL_SYMBOL)==Symbol and Ord(i,VAL_TYPE)==OP_SELL and Ord(i,VAL_TAKEPROFIT)>0 then SellSet=SellSet+1; End; If BuySet==BuyThisSymbol and SellSet==SellThisSymbol Then { trigger=2; };*/ If (HighestBuy-Ask)>=5*Point OR (Bid-LowestSell)>=5*Point Then { if PipsNeeded < 40 And PipsNeeded >=10 And CloseAll==0 Then { If BuyThisSymbol > SellThisSymbol OR SellThisSymbol > BuyThisSymbol Then { If SellThisSymbol > BuyThisSymbol And Set1==0 Then { if BuyOrd < SellOrd and trigger == 0 then { Pips= PipsNeeded*Point; MyStop = Bid - Pips; trigger = 1; Set1=1; If trigger == 1 then trigger2=0; Counter1S=0; Counter1B=0; Set2=0; }; if BuyOrd < SellOrd and trigger == 1 then { Pips= PipsNeeded*Point; Profit = Ask - Pips; trigger = 2; }; }; If BuyThisSymbol > SellThisSymbol And Set2==0 Then { If SellOrd < BuyOrd and trigger2 ==0 Then { Pips= PipsNeeded*Point; MyStop = Ask + Pips; trigger2=1; Set2=1; If trigger2 ==1 then trigger=0; CounterS=0; CounterB=0; Set1=0; }; If BuyOrd > SellOrd and trigger2 ==1 then { Pips = PipsNeeded*Point; Profit = Bid +Pips; trigger2= 2; }; }; if TotalTrades > 19 and trigger > 0 then { for i = 1 to TotalTrades Begin If SellThisSymbol > BuyThisSymbol Then { If BuyOrd > CounterB Then { if ord(i,VAL_SYMBOL) = symbol and ord(i,VAL_TYPE) = OP_BUY and ord(i,VAL_STOPLOSS) = 0 then { ModifyOrder(ord(i,VAL_TICKET),ord(i,VAL_OPENPRICE),MyStop,0,Gold); CounterB=CounterB+1; exit; }; }; If SellOrd > CounterS Then { if ord(i,VAL_SYMBOL) = symbol and ord(i,VAL_TYPE) = OP_SELL and ord(i,VAL_TAKEPROFIT) = 0 then { ModifyOrder(ord(i,VAL_TICKET),ord(i,VAL_OPENPRICE),0,Profit,Gold); CounterS=CounterS+1; exit; }; }; }; If BuyThisSymbol > SellThisSymbol Then { If SellOrd > Counter1S Then { if ord(i,VAL_SYMBOL) = symbol and ord(i,VAL_TYPE) = OP_SELL and ord(i,VAL_STOPLOSS) = 0 then { ModifyOrder(ord(i,VAL_TICKET),ord(i,VAL_OPENPRICE),MyStop,0,Gold); CounterS=Counter1S+1; exit; }; }; If BuyOrd > Counter1B Then { if ord(i,VAL_SYMBOL) = symbol and ord(i,VAL_TYPE) = OP_BUY and ord(i,VAL_TAKEPROFIT) = 0 then { ModifyOrder(ord(i,VAL_TICKET),ord(i,VAL_OPENPRICE),0,Profit,Gold); CounterB=Counter1B+1; exit; }; }; }; End; }; }; }; }; //////////////// // Reset Variables ///////////////// If CloseBuyFirst==1 or CloseSellFirst==1 Then { If BuyThisSymbol==0 Then { CloseBuyFirst=0; }; If SellThisSymbol==0 Then { CloseSellFirst=0; }; }; /////////////////////////////////////////////// // If Profit is positive, close all open positions; //////////////////////////////////////////////// If TotalProfit > ProfitTarget and CloseSwitch==0 then { CloseAll = 1; //////////////////////// TimeClock = Hour; //give time to close all orders TimeMin = Minute; ///////////////////////// CloseSwitch=1; If BuyThisSymbol>SellThisSymbol then { CloseSellFirst=1; }; If SellThisSymbol>BuyThisSymbol Then { CloseBuyFirst=1; }; }; ///////////////////// // Reset Close Order Variable ////////////////////// If ((TotalTrades == 0) And ((Hour-TimeClock)>=1)) then { If TimeMin<=20 OR Minute >=TimeMin Then { CloseAll = 0; CloseSwitch=0; trigger=0; trigger2=0; Set1=0; Set2=0; CounterB=0; CounterS=0; Counter1B=0; Counter1S=0; }; }; ///////////////////////////////////////// // Close All Orders Routine ////////////////////////////////////////// If CloseAll == 1 then { for i = 1 to TotalTrades { If ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_BUY And (CloseBuyFirst==1)OR ((CloseBuyFirst==0) And (CloseSellFirst==0)) then { If Bid-OrderValue(i,VAL_OPENPRICE)<0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Bid,Slippage,LawnGreen); Exit; }; If Bid-OrderValue(i,VAL_OPENPRICE)>0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Bid,Slippage,Gold); Exit; }; }; If ord(i,VAL_SYMBOL) = Symbol and ord(i,VAL_TYPE) = OP_SELL And (CloseSellFirst==1)OR ((CloseBuyFirst==0) And (CloseSellFirst==0)) then { If OrderValue(i,VAL_OPENPRICE)-Ask <0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Ask,Slippage,HotPink); Exit; }; If OrderValue(i,VAL_OPENPRICE)-Ask >0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Ask,Slippage,Gold); Exit; }; }; }; }; ///////////////////////////////////// // Start up Routine ////////////////////////////////////// If (CloseAll==0) Then //If closing switch set to 1 we don't want any more new orders. { ComSwitch=0; If ((DayOfWeek==6) And (Hour>=FriClose) And (BuyThisSymbol==0) and (SellThisSymbol==0)) Then { Comment("Trading has been halted for the weekend, y'all come back now ya hear! ;-)"); ComSwitch=1; Exit; }; //////////////// // Open First Trades; ///////////////// If ((Close[1]>High[2])and (FiveEMA_1>TwentyEMA_1) and (FiveEMA_0>TwentyEMA_0) And (FiveEMA_1>HundredEMA_1)) OR ((Close[1]0) OR (SellThisSymbol>0) Then { If BuyThisSymbol = 0 and FreeMargin > dMargin then { SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If SellThisSymbol = 0 and FreeMargin > dMargin then { SetOrder(OP_SELL,Lots,Bid,Slippage,0,0,Red); Exit; }; ////////////////////////////////////// // Check to set new buy or sell level /////////////////////////////////////// BuyNewLevel = 0; SellNewLevel = 0; For i = 1 to TotalTrades { If ((ord(i,VAL_SYMBOL)== Symbol) and (ord(i,VAL_TYPE) == OP_BUY) and (ord(i,VAL_OPENPRICE) == Ask)) then BuyNewLevel = 1; If ((ord(i,VAL_SYMBOL)== Symbol) and (ord(i,VAL_TYPE) == OP_SELL) and (ord(i,VAL_OPENPRICE) == Bid)) then SellNewLevel = 1; }; //////////////////////////////////////////////////////// // Open additional trades on a grid; //////////////////////////////////////////////////////// If Ask > LowestBuy and BuyNewLevel = 0 and TotalProfit <5 then { If FreeMargin < dMargin then exit; SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If Bid < HighestSell and SellNewLevel = 0 and TotalProfit <5 then { If FreeMargin < dMargin then exit; SetOrder(OP_SELL,Lots,Bid,Slippage,0,0,Red); Exit; }; }; }; Exit;